package demo_0324;

import demo_0319.Person;
import demo_0319.Rectangle;

import java.util.Arrays;
import java.util.Comparator;

class ageCmp implements Comparator<Employee> {
    @Override
    public int compare(Employee o1, Employee o2) {
        return o1.getAge() - o2.getAge();
    }
}
class nameCmp implements Comparator<Employee> {
    @Override
    public int compare(Employee o1, Employee o2) {
        return o2.getName().compareTo(o1.getName());
    }
}
public class Test {
    public static void Sort (Employee[] arr,Comparator<Employee> cmp) {
        Arrays.sort(arr,cmp);
    }
    public static void print (Employee[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getName() + " " + arr[i].getAge() + " " + arr[i].weeklySalary());
        }
    }
    public static void main(String[] args) {
        Employee[] arr = new Employee[3];
        arr[0] = new GdEmployee("李四",18,10000);
        arr[1] = new HourlyEmployee("张三",20,40,100);
        arr[2] = new SaleEmployee("王五",22,100000,0.9);

        System.out.println("======按年龄=======");
        Sort(arr, (o1, o2) -> o1.getAge() - o2.getAge());
        print(arr);
        System.out.println("======按姓名=======");
        Sort(arr,new nameCmp());
        print(arr);
        System.out.println("======按薪资=======");
        Arrays.sort(arr);
        print(arr);
    }
}
